/*
 * Copyright (c) 2006-2023, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2023-10-10     RT-Thread    first version
 */

#include <rtthread.h>
#include "at.h"

#include "bsp/bsp_spi.h"
#include "bsp/bsp_flash.h"

#include "bsp/bsp_can1.h"
#include "bsp/bsp_can2.h"
#include "bsp/bsp_crc.h"
#include "bsp/bsp_uart1.h"
#include "bsp/bsp_uart2.h"
#include "bsp/bsp_uart3.h"
#include "bsp/bsp_i2c.h"

#include "HJComm/HJMasterDevice.h"

#include "app/app_io.h"
#include "app/app_comm.h"
#include "app/app_dctft.h"
#include "app/app_motorcontrol.h"
#include "app/app_arm_control.h"
#include "app/app_eleact.h"
#include "app/app_force_move.h"

#define NODE_ID         1
#define SOFT_VERSION    "1.0.0.2"

/********hw version 2.0*********/
/*
 USART3 -> 工控机
 USART2 -> 蓝牙
 USART1 -> 触摸屏
 USART4 -> 调试串口
 */


#define DBG_TAG "main"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>

extern "C" int main(void)
{
    int count = 1;

    bsp_spi_init();
    bsp_flash_init();
//
    bsp_uart1_init();
    bsp_uart3_init();

    app_dctft_init();

    bsp_can1_init();
    bsp_can2_init();

    app_io_init();
//
    bsp_crc_init();
//
//    bsp_i2c_init();
//
    app_mc_init();
//    app_eleact_init();
    app_arm_init();

//    app_dctft_init();

    app_force_move_init();

//    at_client_init((const char *)"uart2",128);

    Recv_thread_init();//

    LOG_D("Hello RT-Thread!");
    LOG_D("Ver %s", SOFT_VERSION);
    HJDeiviceWrapInit(NODE_ID, (uint8_t*)SOFT_VERSION);

    while (count++)
    {
        uint8_t des_id[4] = { 0, 0, 0, 255};
        char json_req[512] = {0};
        app_req_process(json_req, sizeof(json_req));
        HJDeiviceWrapTxProcess(des_id, (uint8_t*)json_req, strlen(json_req));
//        LOG_D("Hello RT-Thread!");
        rt_thread_mdelay(200);
    }

    return RT_EOK;
}
